package cn.felord.r2dbc.repository;

import cn.felord.r2dbc.domain.Entity;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import reactor.core.publisher.Mono;


public interface BaseDao<T extends Entity> {


    ReactiveMongoTemplate getMongoTemplate();

    Class<T> getTClass();

    default Mono<T> findOneByQuery(Query query) {
        return getMongoTemplate().findOne(query, getTClass());
    }

    default Mono<T> findById(String id) {
        Query query = Query.query(Criteria.where("id").is(id));
        return getMongoTemplate().findOne(query, getTClass());
    }


}
